package edu.gyc.testthread;

class MyThread extends Thread {
    private int pauseFlagNum;

    public MyThread(String name, int pauseFlagNum) {
        super(name);
        this.pauseFlagNum = pauseFlagNum;
    }

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName() +" "+ i);
            if (i == pauseFlagNum) {
                //使用yield方法的线程将由运行状态转变为就绪状态，也就是让出执行的状态，让其他线程得以优先执行
                Thread.yield();
                System.out.println(Thread.currentThread().getName()+":为什么我要让出CPU,天道不公...");
            }
        }
    }
}
public class YieldTest {
    public static void main(String[] args) {
        new MyThread("A", -1).start();
        new MyThread("B", 5).start();

    }
}
